package com.chen10.gobang.controller;

import com.chen10.gobang.common.exception.BusinessException;
import com.chen10.gobang.common.protocal.ResponseResult;
import com.chen10.gobang.common.protocal.ResponseVO;
import com.chen10.gobang.model.dto.GameRecordsPageDTO;
import com.chen10.gobang.model.page.Pager;
import com.chen10.gobang.model.pojo.GameRecords;
import com.chen10.gobang.model.vo.GameRecordsVO;
import com.chen10.gobang.service.GameRecordsService;
import com.chen10.gobang.service.impl.GameRecordsServiceImpl;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/api/records")
public class GameRecordsController {
    @Resource
    private GameRecordsService gameRecordsService;

    /**
     * 分页查询游戏记录
     * @param gameRecordsPageDTO
     * @return
     */
    @PostMapping("/page")
    public ResponseVO<Pager<GameRecordsVO>> getRecordsPageByUserId(@RequestBody GameRecordsPageDTO gameRecordsPageDTO) {
        try{
            return ResponseResult.success(gameRecordsService.getRecordsPageByUserId(gameRecordsPageDTO));
        }catch (BusinessException e){
            return ResponseResult.error(e.getCode(),e.getMessage());
        }
    }
}
